<?php

namespace app\admin\model;

use app\admin\controller\work\Log;
use think\Db;
use think\Model;
use traits\model\SoftDelete;

class Work extends Model
{


    use SoftDelete;


    // 表名
    protected $name = 'work';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text'
    ];



    public function getStatusList()
    {
        return ['2' => __('Status 2')];
    }
    public function getDamageReasonList()
    {
        return ['1' => __('非质量问题'),'2' => __('质量问题')];
    }
    public function isStatus()
    {
        return ['1' => __('否'),'2' => __('是')];
    }
    public function isStatustwo()
    {
        return ['1' => __('否')];
    }
    public function workBaoList()
    {
        return ['0' => __('过保'),'1' => __('在保')];
    }
    public function cidList()
    {
        return ['' => __('请选择'),'待通知寄出' => __('待通知寄出'),'进水机' => __('进水机'),'已换新' => __('已换新'),'不寄' => __('不寄'),'主板坏无法修复' => __('主板坏无法修复'),'其他' => __('其他')];
    }
    public function getproblemList(){
        //return ['1' => __('VIP1'), '2' => __('VIP2'), '3' => __('VIP3'), '4' => __('VIP4'), '5' => __('VIP5'), '6' => __('VIP6'), '7' => __('VIP7'), '8' => __('VIP8')];
        $re_data = [];
        $ret = Db::name("problem")->field("id,name")->select();
        foreach ($ret as $k=>$v){
            $re_data[$v['id']] = $v['name'];
        }
        return $re_data;
    }
    public function getShipper(){
        //return ['1' => __('VIP1'), '2' => __('VIP2'), '3' => __('VIP3'), '4' => __('VIP4'), '5' => __('VIP5'), '6' => __('VIP6'), '7' => __('VIP7'), '8' => __('VIP8')];
        $re_data = [];
        $ret = Db::name("shipper")->field("id,name")->select();
        foreach ($ret as $k=>$v){
            $re_data[$v['id']] = $v['name'];
        }
        return $re_data;
    }
    public function getchannel(){
        //return ['1' => __('VIP1'), '2' => __('VIP2'), '3' => __('VIP3'), '4' => __('VIP4'), '5' => __('VIP5'), '6' => __('VIP6'), '7' => __('VIP7'), '8' => __('VIP8')];
        $re_data = [];
        $ret = Db::name("channel")->field("id,name")->select();
        foreach ($ret as $k=>$v){
            $re_data[$v['id']] = $v['name'];
        }
        return $re_data;
    }
    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function isLiugc()
    {
        return ['2' => __('否'),'1' => __('是')];
    }
    public function ishuangou()
    {
        return ['0' => __('无-修好寄回'),'1' => __('是，旧笔留工厂'),'2' => __('否，旧笔寄回'),'3' => __('否，旧笔留工厂'),'4' => __('否，需维修')];
    }
    public function Product()
    {
        //return $this->belongsTo('Product', 'id', 'product_id')->setEagerlyType(0);
        return $this->belongsTo('Product', 'product_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function User()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function Channel()
    {
        return $this->belongsTo('Channel', 'channel_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function Admin()
    {
        return $this->belongsTo('Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function Factory()
    {
        return $this->belongsTo('Factory', 'factory_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function WorkLog()
    {
        return $this->belongsTo('\\app\\admin\\model\\work\\Log', 'id', 'work_id', [], 'LEFT')->setEagerlyType(0);
    }
}
